const State = {
  sidebar: {
    activeIndex: '',
    opened: false,
    withoutAnimation: false
  },
  time: '',
  month: '',
  keyTime: '',
  device: 'desktop',
  language: 'en',
  size: 'medium'
};

// getters
const Getters = {
  sidebar: state => state.sidebar,
  language: state => state.language,
  size: state => state.size,
  device: state => state.device,
  time: state => state.time,
  month: state => state.month,
  keyTime: state => state.keyTime
};

// mutations
const Mutations = {
  reset: state => {
    const s = {
      sidebar: {
        activeIndex: '',
        opened: false,
        withoutAnimation: false
      },
      time: '',
      month: '',
      keyTime: '',
      device: 'desktop',
      language: 'en',
      size: 'medium'
    };
    Object.keys(s).forEach(key => {
      state[key] = s[key];
    });
  },
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened;
    state.sidebar.withoutAnimation = false;
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    state.sidebar.opened = false;
    state.sidebar.withoutAnimation = withoutAnimation;
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device;
  },
  SET_LANGUAGE: (state, language) => {
    state.language = language;
  },
  SET_SIZE: (state, size) => {
    state.size = size;
  },
  SET_TIME: (state, time) => {
    state.time = time;
  },
  SET_MONTH: (state, month) => {
    state.month = month;
  },
  SET_KEYTIME: (state, keyTime) => {
    state.keyTime = keyTime;
  },
  // sidebar active index
  ACTIVEINDEX: (state, index) => {
    state.sidebar.activeIndex = index;
  }
};
// actions
const Actions = {
  activeIndex({ commit }, index) {
    commit('ACTIVEINDEX', index);
  },
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR');
  },
  closeSideBar({ commit }, { withoutAnimation }) {
    commit('CLOSE_SIDEBAR', withoutAnimation);
  },
  toggleDevice({ commit }, device) {
    commit('TOGGLE_DEVICE', device);
  },
  setLanguage({ commit }, language) {
    commit('SET_LANGUAGE', language);
  },
  setSize({ commit }, size) {
    commit('SET_SIZE', size);
  },
  // 系统数据更新时刻
  setTime({ commit }, time) {
    commit('SET_TIME', time);
  },
  // 系统数据月份更新时间
  setMonth({ commit }, month) {
    commit('SET_MONTH', month);
  },
  // 关键词系统数据更新时间
  setKeyTime({ commit }, keyTime) {
    commit('SET_KEYTIME', keyTime);
  }
};

export default {
  namespaced: true,
  strict: true,
  state: State,
  getters: Getters,
  actions: Actions,
  mutations: Mutations
};
